﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SPThumbnailExtender.Interne
{
    public static class LogManager
    {
        public static void LogInfo(Exception ex)
        {
            string path = "c:\\temp\\log\\" + "Log" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "-" + DateTime.Now.Hour.ToString() + ".txt";
            StreamWriter swErrorLog = null;
            DirectoryInfo dtDirectory = null;
            if (!Directory.Exists("c:\\temp\\log\\"))
            {
                dtDirectory = Directory.CreateDirectory("c:\\temp\\log\\");
                dtDirectory = null;
            }
            if (!File.Exists(path))
            {
                swErrorLog = File.CreateText(path);
            }
            else
            {
                swErrorLog = new StreamWriter(path, true);
            }
            swErrorLog.WriteLine("Date and Time of Exception: " + DateTime.Now);
            swErrorLog.WriteLine("Source of Exception: " + ex.Source);
            swErrorLog.WriteLine(" ");
            swErrorLog.WriteLine("Error Message: " + ex.Message);
            swErrorLog.WriteLine("ToString Message: " + ex.ToString());
            swErrorLog.WriteLine("------------------------------------------- ");
            swErrorLog.WriteLine(" ");
            swErrorLog.Close();
            swErrorLog.Dispose();
            swErrorLog = null;
            if (ex.InnerException != null)
                LogInfo(ex.InnerException);
        }
        public static void LogInfo(String Message)
        {
            string path = "c:\\temp\\log\\" + "Log" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "-" + DateTime.Now.Hour.ToString() + ".txt";
            StreamWriter swErrorLog = null;
            DirectoryInfo dtDirectory = null;
            if (!Directory.Exists("c:\\temp\\log\\"))
            {
                dtDirectory = Directory.CreateDirectory("c:\\temp\\log\\");
                dtDirectory = null;
            }
            if (!File.Exists(path))
            {
                swErrorLog = File.CreateText(path);
            }
            else
            {
                swErrorLog = new StreamWriter(path, true);
            }
            swErrorLog.WriteLine("Date and Time of Exception: " + DateTime.Now);
            swErrorLog.WriteLine("Message: " + Message);
            swErrorLog.WriteLine("------------------------------------------- ");
            swErrorLog.WriteLine(" ");
            swErrorLog.Close();
            swErrorLog.Dispose();
            swErrorLog = null;
        }
    }
}
